//验证时间格式是否正确  日期格式yyyy-mm-dd 
function checkDatetoYMD(time){
    if(!time || time==''){
        return true;
    }
    regTime= /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/;
    var result = false;
    if (regTime.test(time)) {
        return true;
    }
    return result;
}
//验证时间格式是否正确  日期格式yyyy-mm-dd hh:mm:ss
function checkDatetoYMDHMS(time){
    if(!time || time==''){
        return true;
    }
    regTime= /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01]) (0\d{1}|1\d{1}|2[0-3]):[0-5]\d{1}:([0-5]\d{1})$/;
    var result = false;
    if (regTime.test(time)) {
        return true;
    }
    return result;
}

//验证图片格式
var imgType = ["gif", "jpeg", "jpg", "bmp", "png"];
function checkImg(obj){
    if (!RegExp("\.(" + imgType.join("|") + ")$", "i").test(obj.val().toLowerCase())) {
        return false
    }else{
        return true;
    }
}
//验证flash格式
var flashType = ["swf", "fla"];
function checkFlash(obj){
    if (!RegExp("\.(" + flashType.join("|") + ")$", "i").test(obj.val().toLowerCase())) {
        return false
    }else{
        return true;
    }
}

//验证文件格式
var fileType = [];
function checkFile(obj){
    if (!RegExp("\.(" + fileType.join("|") + ")$", "i").test(obj.val().toLowerCase())) {
        return true;//此处需修改
    }else{
        return true;
    }
}
//获取地址栏参数方法
function getUrlParam(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r!=null) return unescape(r[2]); return null; //返回参数值
}
//回车切换元素
$("input,button,select,div").keypress(function (e) {
    // function KeyEnter(e) {

    var v_event = e || window.event;

    var srcElement = v_event.srcElement ? v_event.srcElement : v_event.target;

    var iKeyCode = v_event.keyCode;
    if (iKeyCode == 13 && srcElement.tagName != "TEXTAREA" ) {
        if (srcElement.tagName == "INPUT" && (srcElement.type == "submit" || srcElement.type == "reset")) {
            return false;
        }
        if (srcElement.tagName == "INPUT" || srcElement.tagName == "SELECT" || srcElement.tagName == "BUTTON") {
            var i = 0;
            while (srcElement != srcElement.form.elements[i]) {
                i++;
                if (srcElement.form.elements.length == i)	//一进找到最后一个元素
                    return false;
            }
            //继续循环找到非Disabled和readOnly
            var NextElement = srcElement.form.elements[i + 1];
            for (j = i + 1; j < srcElement.form.elements.length; j++) {
                NextElement = srcElement.form.elements[j];
                if (NextElement.readOnly || (NextElement.disabled == true || NextElement.disabled == 'disabled') || NextElement.style.display == "none") {
                    NextElement = null;
                    continue;
                }
                if (NextElement.tagName == "INPUT") {
                    if (NextElement.type == "hidden") {
                        NextElement = null;
                        continue;
                    }
                }
                //跳过button
                if (NextElement.tagName == "BUTTON") {
                    NextElement = null;
                    continue;
                }
                var fnode = NextElement.parentNode.parentNode;
                if(fnode && fnode.classList.contains('hidden')==true){
                    NextElement = null;
                    continue;
                }
                break;
            }

            if (NextElement) {

                if (srcElement.tagName == "INPUT" && srcElement.type == "file")
                    ;
                else
                    v_event.keyCode = 0;
                try {
                    NextElement.focus();
                }
                catch (e1) {
                    ;
                }
                if (NextElement.tagName == "INPUT") {
                    // v_event.keyCode = 9;
                    if (NextElement.type == "text" || NextElement.type == "password")
                        NextElement.select();
                }
            }
        }
        if (v_event && v_event.stopPropagation) {
            v_event.stopPropagation();
            v_event.preventDefault();
        }
        else {
            v_event.cancelBubble = true;
        }

        return false;
    }

    // }
});